package com.栈;
import java.util.*;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;

public class expEval {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Vector<BigDecimal> nums = new Vector<BigDecimal>();
		Vector<String> vars = new Vector<String>();
		Vector<String> types = new Vector<String>();
		/*
		 * BigDecimal a=new BigDecimal(21); BigDecimal b=new BigDecimal(2); BigDecimal
		 * c=new BigDecimal(11); nums.add(a);nums.add(b);nums.add(c);
		 * vars.add("a");vars.add("b");vars.add("c"); String exp="a/b+c=";
		 * expEval.expEvaluate(exp, vars, nums);
		 */

		while (true) { // operate one line
			String str = sc.nextLine();
			char[] tempStr = str.toCharArray();
			int i, j;
			//if (tempStr[tempStr.length - 1] == '?') {  // calculate
			//}
			// definition situation
			// 1. int a=10;int b=20;
			// 2. int a;
			// int b;
			// a=10;
			// b=20; 
			// 3. int a=10;
			// int b=20; 

			//else {
				for (i = 0; i < tempStr.length; i++) // definition/assignment
				{
					// 1 loop struction, 1 definition/declare;
					int m;
					for (m = i; m < tempStr.length && tempStr[m] != ';' && tempStr[m] != '?'; m++);
					if (m==tempStr.length||tempStr[m] == ';') { // definition or assignment
						for (j = i; j <= m && tempStr[j] != '=' && tempStr[j] != ' '
								&& tempStr[j] != ';'; j++);
						String word = str.substring(i, j);
						// System.out.println(word+tempStr[j]+"*");
						if (word.equals("int") || word.equals("float")) { // define variable
							int k;
							for (k = ++j; k < tempStr.length && tempStr[k] != '=' && tempStr[k] != ' '
									&& tempStr[k] != ';'; k++);
							String tempVar = str.substring(j, k);
							// System.out.println(tempVar+tempStr[k]+"*");
							vars.add(tempVar);
							types.add(word);
							nums.add(new BigDecimal(0));
							// tempStr[k]: ' ' '=' ';'
							if (tempStr[k] == ';') {
								i = k;
							} else if (tempStr[k] == '=') {
								k++;
								int l = k;
								for (; l < tempStr.length && tempStr[l] != ' ' && tempStr[l] != ';'; l++);
								BigDecimal cur_num = new BigDecimal(str.substring(k, l));
								if (word.equals("int")) {
									cur_num = cur_num.setScale(0);
									// System.out.println("int"+cur_num.scale());
								} else {// float
									cur_num = cur_num.setScale(100);
									// System.out.println("float"+cur_num.scale());
								}
								// System.out.println(cur_num.scale());
								nums.set(vars.indexOf(tempVar), cur_num);
								i=l;
							}
						} else if (vars.indexOf(word) != -1) { // assignment
							// tempStr[j]=='='
							j++;
							int l = j;
							for (; l < tempStr.length && tempStr[l] != ' ' && tempStr[l] != ';'; l++)
								;
							BigDecimal cur_num = new BigDecimal(str.substring(j, l));
							if (types.get(vars.indexOf(word)).equals("int")) {
								cur_num = cur_num.setScale(0);
							} else {
								//System.out.println(types.get(vars.indexOf(word)));
								cur_num = cur_num.setScale(2);
							}
							nums.set(vars.indexOf(word), cur_num);
							i = l;
						} else if (vars.indexOf(word) == -1) {
							System.out.println("wrong - variable undefined");
							return;
						}
					}
					else if(tempStr[m]=='?') {
						String exp = str.substring(i,m);
						expEval.expEvaluate(exp, vars, nums);
						return;
					}
				}

			}
		//}

	}

	public static void expEvaluate(String exp, Vector<String> vars, Vector<BigDecimal> nums) {
		char[] i_exp = exp.toCharArray();
		Stack<BigDecimal> douStack = new Stack<BigDecimal>();
		Stack<Character> charStack = new Stack<Character>();
		Vector<Character> o_exp = new Vector<Character>();
		int i;
		Vector<BigDecimal> numStore = new Vector<BigDecimal>();
		int num_count = 0;
		for (i = 0; i < i_exp.length; i++) {
			if (i_exp[i] == ' ' || i_exp[i] == '=')
				continue;
			if (isOperator(i_exp[i])) {
				if (i_exp[i] == '(') {
					int j = i;
					for (; j < i_exp.length && i_exp[j] != ')'; j++)
						;
					if (j == i_exp.length) {
						System.out.println("wrong - error expression");
						return;
					}
				}
				// System.out.print(i_exp[i]);
				// System.out.println(isNumber(i_exp[i]));
				if (pop_judge(charStack, i_exp[i])) // priority or )
				{

					if (i_exp[i] == ')') {
						while (charStack.peek() != '(') // pop until meet the (
						{
							o_exp.add(charStack.peek());
							charStack.pop();
							if (charStack.empty()) // )meet no ( error
							{
								System.out.println("wrong - error expression");
								return;
							}
						}
						charStack.pop(); // pop ( no push )
					} else // priority lower or equal : top>=operator
					{
						while (!charStack.empty() && !priority(charStack.peek(), i_exp[i])) {
							o_exp.add(charStack.peek());
							charStack.pop();
						}
						charStack.push(i_exp[i]);
					}
				} else // priority higher : top < operator no pop just push
				{
					charStack.push(i_exp[i]);
				}
			} else if (isNumber(i_exp[i])) {
				// System.out.print(i_exp[i]);
				// System.out.println(isNumber(i_exp[i]));
				int j = i;
				while (j < i_exp.length && isNumber(i_exp[j])) {
					// System.out.println("j="+j+" i="+i);
					j++;
					// System.out.println(j);
				}
				String cur_num = exp.substring(i, j);

				// System.out.println("current number:"+cur_num);
				BigDecimal num = new BigDecimal(cur_num);
				numStore.add(num);
				o_exp.add((char) (num_count + 48));
				num_count++;

				i = j - 1; // the last number of the data ; i++ in the loop
			} else if (isVariable(i_exp[i])) {
				// System.out.println("variable");
				int j = i;
				while (j < i_exp.length && isVariable(i_exp[j])) {
					// System.out.println("j="+j+" i="+i);
					j++;
					// System.out.println(j);
				}
				String cur_var = exp.substring(i, j);
				// System.out.println(cur_var);

				// System.out.println(cur_num);
				if (vars.indexOf(cur_var) == -1) {
					System.out.println("wrong - variable undefined");
					return;
				}
				BigDecimal cur_num = nums.get(vars.indexOf(cur_var));
				numStore.add(cur_num);
				o_exp.add((char) (num_count + 48));
				num_count++;
				i = j - 1;
			} else { // not number and not operator
				System.out.println("wrong - error expression");
				return;
			}
		}
		while (!charStack.empty()) // charStack empty
		{
			o_exp.add(charStack.peek());
			charStack.pop();
		}
		for (i = 0; i < o_exp.size(); i++) {
			if (o_exp.get(i) == '(' || o_exp.get(i) == ')') // ( not matched
			{
				System.out.println("wrong - error expression");
				return;
			}
		}
		/*
		 * for(i=0;i<numStore.size();i++) System.out.println(numStore.get(i));
		 * System.out.println(o_exp);
		 */
		BigDecimal result = new BigDecimal(String.valueOf(0));
		BigDecimal temp = new BigDecimal(String.valueOf(0));
		for (i = 0; i < o_exp.size(); i++) {
			if (!isOperator(o_exp.get(i))) // push number in douStack index
			{
				douStack.push(numStore.get(o_exp.get(i) - 48));
			} else // meet operators
			{
				BigDecimal left = new BigDecimal(String.valueOf(0)); // ensure there are two+numbers in the douStack
				BigDecimal right = new BigDecimal(String.valueOf(0));
				if (!douStack.empty()) {
					right = douStack.peek();
					douStack.pop();
				} else {
					return;
				}
				if (!douStack.empty()) {
					left = douStack.peek();
					douStack.pop();
				} else {
					return;
				}
				if(right.doubleValue()==0&&o_exp.get(i)=='/'){
					System.out.println("wrong - variable unassigned");
					return;
				}
				temp = calculate(left, o_exp.get(i), right);
				if (o_exp.get(i) == '%' && temp.doubleValue() == -1) { // '%'wrong
					System.out.println("wrong - error expression");
					return;
				} else
					douStack.push(temp);
			}
		}
		if(douStack.empty())System.out.println("empty?");
		result = douStack.peek();
		// if(result.scale()==0) {
		// System.out.print(result.setScale(2));
		// }
		// else
		NumberFormat formatter = new DecimalFormat("#0.00");
		if(result.scale()!=0) {
			String fmresult=formatter.format(result.doubleValue());
			System.out.print(fmresult);
			return;
		}
		else {
			System.out.print(result);
		}
		// sc.close();
	}

	public static boolean isOperator(char c) {
		return (c == '+' || c == '-' || c == '*' || c == '/' || c == '%' || c == '(' || c == ')');
	}

	public static boolean isNumber(char c) {

		if ((c >= 48 && c <= 57) || c == '.')
			return true;
		else
			return false;
	}

	public static boolean isVariable(char c) {
		return ((c >= 65 && c <= 90) || (c >= 97 && c <= 122));
	}

	public static BigDecimal calculate(BigDecimal left, char ope, BigDecimal right) {
		switch (ope) {
		case '+': {
			if (left.scale() == 0 && right.scale() == 0) { // both int
				// System.out.println(left.add(right));
				return left.add(right).setScale(0);
			}
			return left.add(right).setScale(100);
		}
		case '-': {
			if (left.scale() == 0 && right.scale() == 0)
				return left.subtract(right).setScale(0);
			return left.subtract(right).setScale(100);
		}
		case '*': {
			if (left.scale() == 0 && right.scale() == 0) {
				return left.multiply(right).setScale(0);
			}
			return left.multiply(right).setScale(100);
		}
		case '/': {
			//System.out.println(left.scale());
			//System.out.println(right.scale());
			
			if (left.scale() == 0 && right.scale() == 0)
				return left.divide(right, 0, BigDecimal.ROUND_DOWN);
			return left.divide(right, 100, BigDecimal.ROUND_HALF_EVEN);
		}
		case '%': {
			return left.divideAndRemainder(right)[1];
		}
		default: {
			double d = -1;
			return new BigDecimal(String.valueOf(d));
		}
		}
	}

	public static boolean priority(char top, char ope) { // true:top<ope false top>=ope
		if (ope == '(')
			return true;
		else if (ope == ')')
			return false;
		else if (ope == '*' || ope == '/' || ope == '%') {
			if (top == '*' || top == '/' || top == '%')
				return false;
			else if (top == '+' || top == '-')
				return true;
			else if (top == '(')
				return true;
			else if (top == '^')
				return false;
			else
				return true;
		} else if (ope == '+' || ope == '-') {
			if (top == '(')
				return true;
			return false;
		} else {
			return true;
		}
	}

	static Boolean pop_judge(Stack<Character> sta, char ope)
	// false:higher or empty true:lower or equal
	{
		if (sta.empty())
			return false;
		else {
			if (priority(sta.peek(), ope))
				return false;
			else
				return true;
		}
	}
}
